package com.example.myapplication;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;


import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.appcompat.widget.LinearLayoutCompat;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;

import org.json.JSONException;
import org.json.JSONObject;

public class OneActivity extends AppCompatActivity {

    private AppCompatTextView moneyTextView = null;
    private LinearLayoutCompat moneyLinearLayout = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_one);

        moneyTextView = findViewById(R.id.moneyTextView);
        moneyLinearLayout = findViewById(R.id.moneyLinearLayout);

        HttpParams httpParams = new HttpParams();
        httpParams.put("stu_id", "20180506118");
        OkGo.<String>post("http://shop.gxfmwlkj.com/index/index/wechat/").tag(this).params(httpParams).execute(new StringCallback() {
            @SuppressLint("SetTextI18n")
            @Override
            public void onSuccess(Response<String> response) {
                try {
                    JSONObject jsonObject = new JSONObject(response.body());
                    jsonObject = jsonObject.getJSONObject("data");
                    jsonObject = jsonObject.getJSONObject("wechat");
                    moneyTextView.setText("￥" + jsonObject.getString("money"));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });

        moneyLinearLayout.setOnClickListener(view -> {
            Intent intent =new Intent(this,TwoActivity.class);
            intent.putExtra("money",moneyTextView.getText().toString());
            startActivity(intent);
        });
    }
}
